<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="../../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=emulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8">
<link rel="stylesheet" href="${ctx}/css/sapar.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/css/common.css" />
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/sapar.js"></script>
<script type="text/javascript" src="${ctx}/js/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>
<title>编辑档案</title>
<style type="text/css">
.kv-item label{
	width: 90px;
}
.dataSel .iselect-wrapper{
	float: left;
	margin-right: 5px;
	width: 245px;
}

.dataSel .iselect-wrapper .iselect{
	width:245px;
}
</style>
</head>

<body>
    <div id="saper-container">
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>编辑档案</h2>
            </div>
			<div class="subfiled-content">
	            <form class="saper-form" id="dataForm">
	                <div class="kv-item clearfix">
						<label><span class="impInfo">*</span>一次品名称：</label>
	                    <div class="kv-item-content">
	                        <input type="text" placeholder="一次品名称" class="txt_required" name="productName" id="productName" value="${kucun.productName}" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')"  >
	                    </div>
	                </div>
	                <div class="kv-item clearfix">
						<label><span class="impInfo">*</span>一次品规格：</label>
	                    <div class="kv-item-content">
	                        <input type="text" placeholder="一次品规格" class="txt_required" name="productGuige" id="productGuige" value="${kucun.productGuige}" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')"  >
	                    </div>
	                </div>
	                <div class="kv-item clearfix">
	                    <label><span class="impInfo">*</span>一次品价格 ：</label>
	                    <div class="kv-item-content">
	                        <input type="text" placeholder="一次品价格 " class="txt_required" name="productPrice" id="productPrice" value="${kucun.productPrice}">
	                    </div>
	                </div>
					<div class="kv-item clearfix">
	                    <label><span class="impInfo">*</span>入库数量 ：</label>
	                    <div class="kv-item-content">
	                        <input type="text" placeholder="入库数量 " class="txt_required" name="productNum" value="${kucun.productNum}" onkeyup="this.value=this.value.replace(/\D/g,'')">
	                    </div>
	                </div>
	                <div class="kv-item dataSel clearfix">
                        <label>一次品类型：</label>
                        <div class="kv-item-content">
                            <select name="productType">
                                <option>选择类型</option>
                                <option value="0" <c:if test="${kucun.productType==0}">selected="selected"</c:if>>一次品无菌物品</option>
                                <option value="1" <c:if test="${kucun.productType==1}">selected="selected"</c:if>>一次品清洁物品</option>
                            </select>
                        </div>
                    </div>
                    <div class="kv-item dataSel  clearfix">
                        <label>供应商：</label>
                        <div class="kv-item-content">
                            <select name="gongyingshang">
                                <option>选择类型</option>
                                <c:if test="${gysList != null}">
                            	<c:forEach items="${gysList}" var="gys">
                                	<option value="${gys.manufactorId}" <c:if test="${kucun.gongyingshang==gys.manufactorId}">selected="selected"</c:if>>${gys.manufactorName}</option>
                                </c:forEach>
                                </c:if>
                            </select>
                        </div>
                    </div>
	                <div class="kv-item clearfix">
	                    <label>一次品图片 ：</label>
	                    <div class="kv-item-content">
	                    	<input type="hidden" name="productPic" id="productPic" value="${kucun.productPic}"/>
	                    	<input type="file" name="upPicFile" id="upPicFile" value="">
	                        <input type="button" id="uploadPic" value="上传" />
	                    </div>
	                </div>
	                
	                
	                <div class="buttons">
	                    <a href="javascript:;" class="sapar-btn sapar-btn-recom">确定</a>
	                    <input type="hidden" name="productId" id="productId" value="${kucun.productId}"/>
	                </div>
	            </form>
            </div>
        </div>
        <div id="saper-ft"></div>
    </div>


<script src="${ctx}/js/ajaxfileupload.js"></script>
<script type="text/javascript">
function isNullOrEmpty(strVal){
	strVal = strVal.replace(/(^\s*)|(\s*$)/g,"");
	if(strVal == '' || strVal == null || strVal == undefined){
		return true;
	}else{
		return false;
	}
}
$(function(){
	
	 $("#productPrice").keyup(function () {
	      var reg = $(this).val().match(/\d+\.?\d{0,2}/);
	      var txt = '';
	      if (reg != null) {
	          txt = reg[0];
	      }
	      $(this).val(txt);
	 }).change(function () {
		  $(this).keypress();
		  var v = $(this).val();
		  if (/\.$/.test(v)){
		     $(this).val(v.substr(0, v.length - 1));
		  }
	});
	
	$(".sapar-btn-recom").click(function(){
		 var btn = true;
		 $(".txt_required").each(function(){
			 var str =$(this).val();
			 if(isNullOrEmpty(str)){
				 btn = false;
				 layer.msg("必填项不为空");
				 return false;
			 }
		 });
		 if(btn){
			 $.ajax({
	             type: "POST",
	             url:"${ctx}/oneOff/yicipinStoreSave.do",
	             data:$('#dataForm').serialize(),// 你的formid
	             error: function(request) {
	            	 	layer.alert("网络故障，请稍后再试!");
	             },
	             success: function(data) {
	 	           	if(data.status=="true"){
		 	           	layer.alert("保存成功", function(){
		 	           		window.location.href="${ctx}/oneOff/yicipinStoreList.do";
	           		    });
	 	           	}else{
	 	           		 layer.msg(data.msg);
	 	           	}
	             }
	         }); 
		 }
	});
	
	$("#uploadPic").click(function () {
   		 if($("#upPicFile").val()==''){
   			 layer.msg("请选择图片");
			 return false;
   		 }
         ajaxFileUpload();
    });
    
    function ajaxFileUpload() {
        $.ajaxFileUpload
        (
            {
                url: '${ctx}/upload/filesUploadPics.do', //用于文件上传的服务器端请求地址
                secureuri: false, //是否需要安全协议，一般设置为false
                fileElementId: 'upPicFile', //文件上传域的ID
                dataType: 'json', //返回值类型 一般设置为json
                success: function (data, status)  //服务器成功响应处理函数
                {
                	var msg = data.message;
                	if(data.error==1){
                		$("#productPic").val(msg);
                		layer.alert('上传成功', {
	                	    skin: 'layui-layer-lan'
	                	    ,closeBtn: 0
	                	    ,shift: 4 //动画类型
	                    });
                	}else{
                		layer.alert('上传失败,'+msg, {
	                	    skin: 'layui-layer-lan'
	                	    ,closeBtn: 0
	                	    ,shift: 4 //动画类型
	                    });
                	}
                	
                },
                error: function (data, status, e)//服务器响应失败处理函数
                {
                    alert("上传失败");
                }
            }
        )
        return false;
    }
	
});
$('select').iSelect();
</script>    
</body>
</html>